import request from '@/utils/request'

export function listStockTTransaction(query) {
  return request({
    url: '/stock/t/transaction/list',
    method: 'post',
    data: query
  })
}

// 分页查询股票T交易
export function pageStockTTransaction(query) {
  // 分离分页参数和查询参数
  const { pageNum, pageSize, orderByColumn, isAsc, ...searchParams } = query;
  
  return request({
    url: '/stock/t/transaction/page',
    method: 'post',
    data: searchParams, // 查询参数放在请求体中
    params: {  // 分页参数和排序参数放在URL参数中
      pageNum: pageNum,
      pageSize: pageSize,
      orderByColumn: orderByColumn,
      isAsc: isAsc
    }
  })
}

export function getStockTTransaction(id) {
  return request({
    url: `/stock/t/transaction/${id}`,
    method: 'get'
  })
}

export function addStockTTransaction(data) {
  return request({
    url: '/stock/t/transaction',
    method: 'post',
    data: data
  })
}

export function updateStockTTransaction(data) {
  return request({
    url: '/stock/t/transaction',
    method: 'put',
    data: data
  })
}

export function delStockTTransaction(id) {
  return request({
    url: `/stock/t/transaction/${id}`,
    method: 'delete'
  })
}

// 批量删除股票T交易
export function batchDeleteStockTTransaction(ids) {
  return request({
    url: '/stock/t/transaction/batch',
    method: 'delete',
    data: ids
  })
}

// 添加保存方法（兼容新增和更新）
export function saveStockTTransaction(data) {
  return request({
    url: '/stock/t/transaction/save',
    method: 'post',
    data: data
  })
}

// 根据股票代码和交易日期查询做T交易记录
export function listStockTTransactionByStockAndDate(stockCode, transactionDate) {
  return request({
    url: '/stock/t/transaction/list',
    method: 'post',
    data: {
      stockCode: stockCode,
      transactionDate: transactionDate
    }
  })
}

// 获取指定日期所有股票的做T总收益
export function getTotalTProfitByDate(transactionDate) {
  return request({
    url: '/stock/t/transaction/total-t-profit',
    method: 'post',
    data: {
      transactionDate: transactionDate
    }
  })
}

// 获取指定日期和股票的做T总收益
export function getTotalTProfitByStockAndDate(stockCode, transactionDate) {
  return request({
    url: '/stock/t/transaction/total-t-profit-by-stock',
    method: 'post',
    data: {
      stockCode: stockCode,
      transactionDate: transactionDate
    }
  })
}

// 获取指定股票的做T总收益
export function getTotalTProfitByStockCode(stockCode) {
  return request({
    url: '/stock/t/transaction/totalTProfitByStockCode',
    method: 'post',
    data: {
      stockCode: stockCode
    }
  })
}
